﻿/// <reference path="base/framwork.js" />

function FuturePay() {
    if ($('#txt_jie1').val() == '') {
        icom.alert('请输入接引');
        return;
    }


    var jie = [];

    if ($('#txt_jie1').val() != '') jie[0] = $('#txt_jie1').val();
    if ($('#txt_jie2').val() != '') jie[1] = $('#txt_jie2').val();

    var yang = [];

    if ($('#txt_yang1').val() != '') yang[0] = $('#txt_yang1').val();
    if ($('#txt_yang2').val() != '') yang[1] = $('#txt_yang2').val();

    $.get('/webajax/OrderHandler.ashx', { method: 'FuturePay', jie: jie.join(','), yang: yang.join(','), id: icom.getQueryString('id') }, function (data) {

        WeChatPay(data, function (res) {
            var oid = data.OrderID;
            $.get("/webajax/RefOrder.ashx?oid=" + oid, function (res) {
                icom.alert('登记成功', 'reg.html');
                //location.href = 'reg_ok.html?num=' + data.Number;
            });
        })
    }, 'json');
}

function BornPay() {

    if ($('#txt_name1').val() == '') {
        icom.alert('请输入姓名');
        return;
    }

    var name = [];

    if ($('#txt_name1').val() != '') name[0] = $('#txt_name1').val();
    if ($('#txt_name2').val() != '') name[1] = $('#txt_name2').val();
    if ($('#txt_name3').val() != '') name[2] = $('#txt_name3').val();
    if ($('#txt_name4').val() != '') name[3] = $('#txt_name4').val();
    if ($('#txt_name5').val() != '') name[4] = $('#txt_name5').val();

    $.get('/webajax/OrderHandler.ashx', { method: 'BornPay', name: name.join(','), id: icom.getQueryString('id') }, function (data) {
        WeChatPay(data, function (res) {
            var oid = data.OrderID;
            $.get("/webajax/RefOrder.ashx?oid=" + oid, function (res) {
                icom.alert('登记成功', 'reg.html');
                //location.href = 'reg_ok.html?num=' + data.Number;
            });

        })
    }, 'json');

}

function MeritsPay() {
    var amount = $('#txt_Amount').val(),
        typeid = $('#txt_Amount').attr('data-type-id');

    if (amount != '') {
        $.get('/webajax/OrderHandler.ashx', { method: 'MeritsPay', amount: amount, tid: typeid }, function (data) {
            WeChatPay(data, function (res) {
                var oid = data.OrderID;
                $.get("/webajax/RefOrder.ashx?oid=" + oid, function (res) {
                    icom.alert('捐赠成功');
                });
            });
        }, 'json');
    }
}

function DaysPay() {
    $.get('/webajax/OrderHandler.ashx', { method: 'DaysPay' }, function (data) {
        WeChatPay(data, function (res) {
            var oid = data.DayID;
            $.get("/webajax/RefDayOrder.ashx?oid=" + oid, function (res) {
                $('.btn_day').hide();
                icom.alert('捐赠成功');
            });
        });
    }, 'json');
}

function WeChatPay(data, callback) {
    wx.chooseWXPay({
        timestamp: data.timeStamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
        nonceStr: data.nonceStr, // 支付签名随机串，不长于 32 位
        package: data.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
        signType: data.signType, // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
        paySign: data.paySign, // 支付签名
        success: callback
    });
}

